PROJECT_PATH := $(shell pwd)
PROJECT_NAME ?= $(shell basename $(PROJECT_PATH))
PROJECT_BRANCH ?= $(shell git symbolic-ref --short -q HEAD)
PROJECT_VERSION ?= $(shell git describe --abbrev=0 --tags)
PROJECT_TAG ?= $(shell git describe --abbrev=0 --tags)
PROJECT_ARCH ?= "amd64"
PROJECT_REPOSITORY ?= "dockerhub.deepglint.com/deepface/$(PROJECT_NAME)"
RELEASE_FROM ?= "docker"
CONFIG_PATH ?= "$(PROJECT_PATH)/config.yaml"

.PHONY: info clear build

info: ## 打印信息
	@echo "项目路径: $(PROJECT_PATH)"
	@echo "项目名称: $(PROJECT_NAME)"
	@echo "项目分支: $(PROJECT_BRANCH)"
	@echo "项目版本: $(PROJECT_VERSION)"
	@echo "项目Tag: $(PROJECT_TAG)"
	@echo "编译平台: $(PROJECT_ARCH)"
	@echo "镜像名称: $(PROJECT_REPOSITORY)"
	@echo "发布方式: $(RELEASE_FROM)"

clear: ## 清理
	@echo "清理开始"
	@rm -rf bin/*
	@echo "清理完成"

build: ## 编译
	@make info
	@make clear
	@echo "编译开始"
	@CGO_ENABLED=0 GOOS=linux GOARCH=$(PROJECT_ARCH) go build -mod=vendor -v -o bin/$(PROJECT_NAME)
	@echo "编译完成"


help: ## 帮助信息
	@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
